<?php

/**
 * 时间设置
 */
if (!defined('IN_DIALOG'))
    die("Access Denied");

if (Utils::submitCheck('updatesubmit')) {
    $timezone = $_POST['timezone'];
    $dateformat = $_POST['dateformat'];
    $mail_server = $_POST['mail_server'];
    $mail_username = $_POST['mail_username'];
    $mail_password = $_POST['mail_password'];
    $pagesize = (int) $_POST['pagesize'];
    foreach (array('timezone', 'pagesize', 'dateformat', 'mail_server', 'mail_username', 'mail_password') as $variable) {
        $sql = "INSERT INTO " . Utils::tname('config') . "(variable,value)VALUES('" . $variable . "'" . ",'" . $$variable . "')";
        $sql.=" ON DUPLICATE KEY UPDATE value='" . $$variable . "'";
        $_SGLOBAL['db']->query($sql);
    }
    Config::updateConfig('config');

    Utils::showMessage('do_success');
} else {
    $query = $_SGLOBAL['db']->query("SELECT * FROM " . Utils::tname('config'));
    $config = array();
    while ($row = $_SGLOBAL['db']->fetchArray($query)) {
        $config[$row['variable']] = $row['value'];
    }
    $timezone[$config['timezone']] = " selected";

    $_SGLOBAL['view']->assign('timezone', $timezone);
    $_SGLOBAL['view']->assign('config', $config);
    $_SGLOBAL['view']->display('setup_global');
}
?>
